<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>个人网站即时支付解决方案</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <meta name="description" content="个人网站收款 个人收款 个人网站支付 个人支付 在线支付 在线付款 即使到账接口 嵌入支付">
    <style>
        body {
            text-align: center;
            background-color: #e0e0e0
        }

        #app {
            margin: 0 auto
        }

        #app h2 {
            padding-top: 3%
        }

        #intro {
            padding-top: 2%;
            text-align: center
        }

        #app img {
            padding-top: 3%;
            width: 280px
        }

        #app input {
            margin: 1%;
        }
    </style>
</head>
<body>
<div id="app">
    <h2>在线收款Demo</h2>
    <div id="intro">
        1. 支持支付宝、微信、储蓄卡，扫码付款<br>
        2. 无需公司资质、无需接入支付宝、微信<br>
        3. 基于有赞云可信赖,费率低每笔交易1%<br>
    </div>
    <img :src="qrCode">
    <div id="input_price">
        付款金额(元)：<input v-model="obj.amount"><br/>
        付款备注：<input v-model="obj.payReason"><br/>
        <button @click="generate">点此生成支付二维码</button>
    </div>
</div>
</body>

<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
<script>
    var opsId = "";
    var ws = new WebSocket("ws://127.0.0.1:8081/paySocket");
    var app = new Vue({
        el: "#app",
        data: {
            qrCode: "https://img.yzcdn.cn/upload_files/2017/11/25/FlaMfOlko4gdrls7LmdfHDtoACxK.jpg",
            obj: {
                amount: 1,
                payReason: '赞赏支付'
            }
        },
        methods: {
            generate: function () {
                opsId = Math.random();
                ws.send(JSON.stringify(this.obj));
            }
        }
    });
    ws.onmessage = function (data) {
        if (data == null) return;
        var rsp = JSON.parse(data.data);
        if (rsp.code !== 200) {
            alert("服务异常");
            return;
        }
        if (opsId !== '') {
            if (rsp.status === "WAIT_BUYER_PAY") {
                app.qrCode = "https://img.yzcdn.cn/upload_files/2017/11/25/FqZjK96_t4g3PYC7m58RHXQ4PCRm.png"
            }
            if (rsp.status === "PAID") {
                app.qrCode = "https://img.yzcdn.cn/upload_files/2017/11/25/FnFa-_giR389G_rtBBWspFw8esc7.png"
                opsId = '';
            }
            if (rsp.status === "GET_QR_CODE") {
                app.qrCode = rsp.qrCode
            }
        }
    };
</script>
</html>